﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta><style>/*<![CDATA[*/

table{border: 1px solid gray;}
td{border: 1px dotted gray;}
p{margin: 3px 0 3px 0; padding: 0;}
#ID_Footer{font-size: small; font-style: italic; text-align: right; margin-top: 4em; padding-top: 4px; border-top: 2px solid gray;}

/*]]>*/</style><title>第8章 设计Web数据库</title></head><body>
<div style="text-align: center"><span style="font-family: 宋体; font-size: 26pt; font-weight: bold; padding-left: 21pt; line-height: 190%">第二篇</span><span style="font-family: Calibri; font-size: 26pt; font-weight: bold; padding-left: 21pt; line-height: 190%"> </span><span style="font-family: 宋体; font-size: 26pt; font-weight: bold; padding-left: 21pt; line-height: 190%">使用</span><span style="font-family: Calibri; font-size: 26pt; font-weight: bold; padding-left: 21pt; line-height: 190%">MySQL</span></div>
<div><span style="font-family: 微软雅黑; font-size: 18pt; padding-left: 49pt; line-height: 190%">第</span><span style="font-family: Consolas; font-size: 18pt; padding-left: 49pt; line-height: 190%">8</span><span style="font-family: 微软雅黑; font-size: 18pt; padding-left: 49pt; line-height: 190%">章 &nbsp; &nbsp; &nbsp; &nbsp;设计</span><span style="font-family: Consolas; font-size: 18pt; padding-left: 49pt; line-height: 190%">Web</span><span style="font-family: 微软雅黑; font-size: 18pt; padding-left: 49pt; line-height: 190%">数据库</span></div>
<div><span style="font-family: 微软雅黑; font-size: 14pt; padding-left: 70pt; line-height: 170%">8.1 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 14pt; padding-left: 70pt; line-height: 170%">关系数据库的概念 P155</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; color: #000000; line-height: 160%">8.1.1 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; color: #000000; line-height: 160%">表格</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">关系数据库由</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 170%">关系</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">组成，这些关系通常称为</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 170%">表格</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">。</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">表具有</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">名称</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">，若干</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">数据列</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">，每一列对应不同的</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">数据</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">；每个客户一个</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">数据行</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">。</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">8.1.2 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">列</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">每一列有都唯一的</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">名称</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">，列也叫做</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">域</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">或者</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">属性</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">。</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">8.1.3 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">行</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">表中的每一行代表一个客户</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">行也称为</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">记录</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">或</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">元组</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">（</span><span style="font-family: Consolas; font-size: 12pt; line-height: 240%">tuple</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">）</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">8.1.4 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">值</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">每个值必须与该列定义的数据类型相同</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">8.1.5 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">键</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">识别表中的每一特定的客户</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">表中的标志列称为</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #ff0000; line-height: 170%">键</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">或</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #ff0000; line-height: 170%">主键</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">，可能由一列或多列组成。</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">数据库由多个表组成，可以使用</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">键</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">作为表格之间的引用，即</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">外键</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">。（出现在其他表中的某一表中的主键）</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">8.1.6 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">模式</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">数据库整套表格的完整设计称为数据库的</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #ff0000; line-height: 170%">模式</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">。</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">一个模式应该显示表格的</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 170%">列</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">、每个表的</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 170%">主键</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">和</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 170%">外键</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">。</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">可以用带有下画线的元素表示该元素是所在关系的主键，</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 170%">斜体</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">元素表示</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 170%">外键</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">。</span></div>
<div><span style="font-family: Consolas; font-size: 11pt; color: #c45911; padding-left: 21pt; line-height: 160%">Customers(</span><span style="font-family: Consolas; font-size: 11pt; text-decoration: underline; color: #c45911; padding-left: 21pt; line-height: 160%">CustomerID</span><span style="font-family: Consolas; font-size: 11pt; color: #c45911; padding-left: 21pt; line-height: 160%">, Name, Address, City)</span></div>
<div><span style="font-family: Consolas; font-size: 11pt; padding-left: 21pt; line-height: 240%">Orders(</span><span style="font-family: Consolas; font-size: 11pt; text-decoration: underline; padding-left: 21pt; line-height: 240%">OrderID</span><span style="font-family: Consolas; font-size: 11pt; padding-left: 21pt; line-height: 240%">, </span><span style="font-family: Consolas; font-size: 11pt; font-style: italic; padding-left: 21pt; line-height: 240%">CustomerID</span><span style="font-family: Consolas; font-size: 11pt; padding-left: 21pt; line-height: 240%">, Amount, Date)</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">8.1.7 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">关系</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">外键</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">表示两个表格数据之间的关系</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">分为</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 170%">一对一</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">、</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 170%">一对多</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">、</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 170%">多对多</span><span style="font-family: Consolas; font-size: 12pt; line-height: 170%">3</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">种关系。</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">一对多关系中，包含多行的表对应于包含一行的表应该有一个外键。</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">多对多关系中，可用第三个表来（仅）包含其他两个表中的键，将其作为</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">外键对</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">。</span></div>
<div><br /></div>
<div><span style="font-family: 微软雅黑; font-size: 14pt; font-weight: bold; padding-left: 70pt; line-height: 170%">8.2 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 14pt; font-weight: bold; padding-left: 70pt; line-height: 170%">设计</span><span style="font-family: Calibri; font-size: 14pt; font-weight: bold; padding-left: 70pt; line-height: 170%">Web</span><span style="font-family: 宋体; font-size: 14pt; font-weight: bold; padding-left: 70pt; line-height: 170%">数据库</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">要建模的每一种现实世界对象都需要有自己的表</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">8.2.1 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">避免保存冗余的数据（</span><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">p159</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">）</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">需要避免</span><span style="font-family: Consolas; font-size: 12pt; line-height: 240%">3</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">种情况的更新不规则：修改、插入和删除不规则。</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">8.2.2 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">使用原子列值</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">原子列值，即对每一行的每个属性只存储一个数据</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">当两个对象存在多对多的关系时，建立两个表的关联表。</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">8.2.3 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">选择有意义的键</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">关联表中两个外键组合的外键对可以考虑作为键。</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">8.2.4 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">避免多个空属性的设计</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">行上没有值的属性，叫</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; line-height: 240%">空值</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">。</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">8.2.5 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #000000; line-height: 160%">表格类型的总结</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">描述现实世界对象的</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #ff0000; line-height: 170%">简单表</span></div>
<div><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">描述两个现实世界对象的多对多关系的</span><span style="font-family: 宋体; font-size: 12pt; font-weight: bold; color: #ff0000; line-height: 240%">关联表</span><span style="font-family: 宋体; font-size: 12pt; line-height: 240%">。</span></div>
<div><br /></div>
<div><span style="font-family: 微软雅黑; font-size: 14pt; font-weight: bold; padding-left: 70pt; line-height: 170%">8.3 &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: Calibri; font-size: 14pt; font-weight: bold; padding-left: 70pt; line-height: 170%">Web</span><span style="font-family: 宋体; font-size: 14pt; font-weight: bold; padding-left: 70pt; line-height: 170%">数据库架构</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; line-height: 170%">Web</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">数据库系统的外部架构</span></div>
<div><span style="font-family: 宋体; font-size: 10pt; font-weight: bold; padding-left: 40pt; line-height: 160%">* &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 11pt; padding-left: 40pt; line-height: 160%">浏览器</span></div>
<div><span style="font-family: 宋体; font-size: 10pt; font-weight: bold; padding-left: 40pt; line-height: 160%">* &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: Consolas; font-size: 11pt; padding-left: 40pt; line-height: 160%">Web</span><span style="font-family: 宋体; font-size: 11pt; padding-left: 40pt; line-height: 160%">服务器</span></div>
<div><span style="font-family: 宋体; font-size: 10pt; font-weight: bold; padding-left: 40pt; line-height: 160%">* &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: Consolas; font-size: 11pt; padding-left: 40pt; line-height: 160%">PHP</span><span style="font-family: 宋体; font-size: 11pt; padding-left: 40pt; line-height: 160%">引擎</span></div>
<div><span style="font-family: 宋体; font-size: 10pt; font-weight: bold; padding-left: 40pt; line-height: 240%">* &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: Consolas; font-size: 11pt; padding-left: 40pt; line-height: 240%">MySQL</span><span style="font-family: 宋体; font-size: 11pt; padding-left: 40pt; line-height: 240%">服务器</span></div>
<div><span style="font-family: Consolas; font-size: 12pt; line-height: 170%">PHP</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">应用程序分层（</span><span style="font-family: Consolas; font-size: 12pt; line-height: 170%">p163</span><span style="font-family: 宋体; font-size: 12pt; line-height: 170%">）</span></div>
<div><span style="font-family: 宋体; font-size: 10pt; font-weight: bold; padding-left: 40pt; line-height: 160%">* &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 11pt; padding-left: 40pt; line-height: 160%">与</span><span style="font-family: Consolas; font-size: 11pt; padding-left: 40pt; line-height: 160%">MySQL</span><span style="font-family: 宋体; font-size: 11pt; padding-left: 40pt; line-height: 160%">交互的数据库层</span></div>
<div><span style="font-family: 宋体; font-size: 10pt; font-weight: bold; padding-left: 40pt; line-height: 160%">* &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 11pt; padding-left: 40pt; line-height: 160%">包含应用程序核心的业务逻辑层</span></div>
<div><span style="font-family: 宋体; font-size: 10pt; font-weight: bold; padding-left: 40pt; line-height: 160%">* &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 11pt; padding-left: 40pt; line-height: 160%">管理</span><span style="font-family: Consolas; font-size: 11pt; padding-left: 40pt; line-height: 160%">HTML</span><span style="font-family: 宋体; font-size: 11pt; padding-left: 40pt; line-height: 160%">输出的表示层</span></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div>
<div><br /></div><script type="text/javascript" language="javascript" src="jquery.js"></script><script type="text/javascript" language="javascript" src="itemlink.js"></script></body></html>